﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace 客户端
{
    public partial class Register : Form
    {
        public Register()
        {
            InitializeComponent();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void btn_register_Click(object sender, EventArgs e)
        {
            string Caccount = caccount.Text.Trim();
            string Cpassword = cpassword.Text;
            string Cname = cname.Text;
            string Cnumber = cnumber.Text;
            string Caddress = caddress.Text;
            string constr = login.constr;
            // 建立SqlConnection对象
            SqlConnection con = new SqlConnection(constr);
            // 打开连接
            con.Open();
            // 指定SQL语句
            SqlCommand COM = new SqlCommand("select Caccount from Customer where Caccount='" + Caccount + "'", con);
            SqlDataAdapter da = new SqlDataAdapter(COM);
            DataSet ds = new DataSet();

            int n = da.Fill(ds, "添加客户账号");

            if (n != 0)
            {
                MessageBox.Show("账号重复", "提示");
                return;
            }
            else
            {
                SqlCommand com = new SqlCommand("INSERT INTO Customer(Caccount,Cpassword,Cname,Cnumber, Caddress)VALUES('" + Caccount + "','" + Cpassword + "','" + Cname + "','" + Cnumber + "','" + Caddress + "')", con);
                SqlDataReader sdr = com.ExecuteReader();
                MessageBox.Show("注册成功", "提示");
                this.Close();
            }
        }
    }
}
